export const get=(url,params)=>{
	let token: any='';
	if(uni.getStorageSync('token') != null){
		token = uni.getStorageSync('token').result
	}
    return new Promise((resolve,reject)=>{
        uni.request({
            url: url, //仅为示例，并非真实接口地址。
            data: params,
            header: {
                'Content-Type':'application/json;charset=utf-8',
				"AuthorizationappUser":token
            },
            timeout: 3000,
            success(result) {
                resolve(result.data);
            },
            fail(error){
                reject(error);
            }
        });
    })
}
export const post=(url,data)=>{
	let token: any='';
	if(uni.getStorageSync('token') != null){
		token = uni.getStorageSync('token').result
	}
	console.log("haode"+url)
    return new Promise((resolve,reject)=>{
        uni.request({
            url: url, //仅为示例，并非真实接口地址。
            data: JSON.stringify(data),
            method:'POST',
            timeout: 3000,
            header: {
                'Content-Type':'application/json;charset=utf-8',
				"AuthorizationappUser":token
            },
            success(result) {
                resolve(result.data);
            },
            fail(error){
                reject(error);
            }
        });
    });
}
export const put=(url,data)=>{
	let token: any='';
	if(uni.getStorageSync('token') != null){
		token = uni.getStorageSync('token').result
	}
    return new Promise((resolve,reject)=>{
        uni.request({
            url: url, //仅为示例，并非真实接口地址。
            data: JSON.stringify(data),
            method:'PUT',
            timeout: 3000,
            header: {
                'Content-Type':'application/json;charset=utf-8',
				"AuthorizationappUser":token
            },
            success(result) {
                resolve(result.data);
            },
            fail(error){
                reject(error);
            }
        });
    });

}
export const del=(url,data)=>{
	let token: any='';
	if(uni.getStorageSync('token') != null){
		token = uni.getStorageSync('token').result
	}
    return new Promise((resolve,reject)=>{
        uni.request({
            url:url, //仅为示例，并非真实接口地址。
            method:'DELETE',
            data: JSON.stringify(data),
            timeout: 3000,
            header: {
                'Content-Type':'application/json;charset=utf-8',
				"AuthorizationappUser":token
            },
            success(result) {
                resolve(result.data);
            },
            fail(error){
                reject(error);
            }
        });
    })
}
export const baseUrl="http://192.168.31.254:8080";
uni.addInterceptor('request',{
    invoke(args){
        if (args.url == 'https://apis.map.qq.com/ws/place/v1/search'){
        }else{
            args.url=baseUrl+args.url
        }
		let obj = uni.getStorageSync('token')
		if(obj){
			let token = obj.result;
			let expiretime= obj.expiredTime
			const now = new Date().getTime()
			if(now > expiretime){
				uni.removeStorageSync('token')
				uni.removeStorageSync('user')
				uni.removeStorageSync('login')
			}
		}
    },
    success(args){
		if(args.data.code === 401){
			uni.removeStorageSync('token')
			uni.removeStorageSync('user')
			uni.setStorageSync('login',true)
		}else if(args.data.code === 500){
			uni.showToast({
				title:args.data.msg,
				success() {
				}
			})
		}
    },
    fail(err){
    }
})